package com.example.aop.source;

import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;
import org.springframework.scheduling.annotation.AsyncResult;

public class Test {

    public void testAop() {
        TestMethod delegate = new TestMethod();
        //准备通知
        TestMethodInterceptor interceptor = new TestMethodInterceptor();
        ProxyFactory factory = new ProxyFactory();
        //准备切点
        JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
        pointcut.setPattern("com.example.aop.source.TestMethod.*");
        //切面 = 切点 + 通知
        Advisor advisor = new DefaultPointcutAdvisor(pointcut, interceptor);
        //给代理工厂一个切面
        factory.addAdvisor(advisor);
        //需要被代理的对象
        factory.setTarget(delegate);
        TestMethod proxy = (TestMethod) factory.getProxy();
        proxy.test();


        new AsyncResult<String>("");
    }

}
